package com.example.zhxy.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.example.zhxy.model.Clazz;
import com.example.zhxy.service.ClazzService;
import com.example.zhxy.mapper.ClazzMapper;
import org.springframework.stereotype.Service;
import org.springframework.util.StringUtils;

/**
* @author fzykd
* @description 针对表【tb_clazz】的数据库操作Service实现
* @createDate 2023-03-13 21:26:35
*/
@Service
public class ClazzServiceImpl extends ServiceImpl<ClazzMapper, Clazz>
    implements ClazzService{


    @Override
    public IPage getClazzByOpr(Page<Clazz> page, Clazz clazz) {
        //创建一个条件构造器
        LambdaQueryWrapper<Clazz> queryWrapper = new LambdaQueryWrapper<>();
        //前端传来两个参数的判断
        if (clazz != null){
            //通过年级等值查询 LambdaQueryWrapper 自带判断参数
            queryWrapper.eq(!StringUtils.isEmpty(clazz.getGradeName()),Clazz::getGradeName,clazz.getGradeName());
            //通过班级名称 模糊查询
            queryWrapper.like(!StringUtils.isEmpty(clazz.getName()),Clazz::getName,clazz.getName());

        }
        //根据id升序排列
        queryWrapper.orderByAsc(Clazz::getId);
        return baseMapper.selectPage(page,queryWrapper);
    }
}




